package cn.xej.easyexcel.export.impl;

import cn.xej.easyexcel.common.BaseQuery;
import cn.xej.easyexcel.export.AbstractExportService;
import cn.xej.easyexcel.export.excelcolumn.BookColumn;
import cn.xej.easyexcel.mapper.BookMapper;
import cn.xej.easyexcel.pojo.Book;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author <a href="mailto:enjie.xu@yunhutech.com">xiaoming</a>
 * @since 2021/6/7
 *
 * 书本导出excel实现类
 */
@Service("exportBookService")
public class ExportBookService extends AbstractExportService<BaseQuery> {
    @Resource
    private BookMapper bookMapper;

    @Override
    public Class<BaseQuery> paramClass() {
        return BaseQuery.class;
    }

    @Override
    public String title() {
        return "书本记录";
    }

    @Override
    public String makefile(BaseQuery request) {
        List<BookColumn> dataList = new ArrayList<>();
        List<Book> books = bookMapper.getBooks();
        books.forEach(b -> {
            BookColumn column = new BookColumn();
            BeanUtils.copyProperties(b,column);
            dataList.add(column);
        });

        return super.writeExcel(BookColumn.class,dataList);
    }
}
